Object.defineProperty(exports, "__esModule", {
  value: true
});
var $2EventCenter = require("EventCenter");
var $2Platformconf = require("Platformconf");
var cc__decorator = cc._decorator;
var ccp_ccclass = cc__decorator.ccclass;
var ccp_property = cc__decorator.property;
var def_GridAdMgr = /* */function () {
  function _ctor() {
    babel_classCallCheck(this, _ctor);
    this.OnShowCallback = new Map();
    this.OnDestroyCallback = new Map();
    this.OnHideCallback = new Map();
    this.gridAds = new Map();
    this.isDestroy = true;
    this.isError = false;
    this.gridAdOpen = new Map();
  }
  return babel_createClass(_ctor, [{
    key: "Create",
    value: function Create(e, t, n) {
      var s = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "black";
      console.log("创建格子广告:", e);
      console.log("格子广告数量:", n);
      if (window.wx && !this.gridAds.get(e)) {
        var _a17 = wx.createGridAd({
          adUnitId: e,
          adTheme: s,
          gridCount: n,
          style: {
            left: t.left,
            top: t.top,
            width: t.width,
            opacity: .8
          },
          adIntervals: 120
        });
        _a17.onLoad(function () {
          console.log("格子广告加载成功");
        });
        _a17.onError(function (t) {
          console.log("格子广告加载错误", JSON.stringify(t), e);
          var n = 0;
          for (var _o46 = 0; _o46 < $2Platformconf.default.Instance.getconfig().WXGame.GridAd.length; _o46++) {
            if ($2Platformconf.default.Instance.getconfig().WXGame.GridAd[_o46] == e) {
              n = _o46;
              break;
            }
          }
          $2EventCenter.default.postEvent("change_custom", n);
        });
        this.gridAds.set(e, _a17);
      }
    }
  }, {
    key: "Show",
    value: function Show(e, t, n) {
      var _this43 = this;
      var o = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : "black";
      this.gridAds.has(e) || this.Create(e, t, n, o);
      this.gridAdOpen.set(e, true);
      this.gridAds.get(e).show().then(function () {
        0 == _this43.gridAdOpen.get(e) && _this43.Hide(e);
        console.log("格子广告显示");
      });
    }
  }, {
    key: "Hide",
    value: function Hide(e) {
      console.log("隐藏格子广告:", e);
      if (this.gridAds.has(e)) {
        this.gridAds.get(e).hide();
        this.gridAdOpen.set(e, false);
      }
    }
  }, {
    key: "Destroy",
    value: function Destroy(e) {
      if (this.gridAds.has(e)) {
        console.log("销毁格子广告:", e);
        this.gridAds.get(e).hide();
        this.gridAds.get(e).offError();
        this.gridAds.get(e).destroy();
        this.gridAds.delete(e);
      }
    }
  }], [{
    key: "Instance",
    get() {
      _ctor._instance || (_ctor._instance = new _ctor());
      return _ctor._instance;
    }
  }]);
}();
exports.default = def_GridAdMgr;